<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
    </script>
</head>
<body>
    前端生成签名

</body>
<script src="../javaScript-MD5/js/md5.js"></script>
<script>
    // # 获取所有请求的参数
    // # 签名规则
    // # 第一步 参与签名的参数不包括签名本身、不包括token
    // # 第二步 按照ASCII排序
    // # 去除多余的& 符号
    var params = new Array();
    params['id'] = 1;
    params['name'] = '张三';
    var sign = createSign(params);
    params['sign'] = sign;
    var url = 'http://pyg.com/list?'
    for (var i in params) {
        url += i + '=' + params[i] + '&';
    }
    $.ajax({
        url:url,
        dataType:'json',
        success:function (result) {
            console.log(result);
        }
    })
    function createSign(params) {
        var timestamp = Math.ceil((new Date()).getTime()/1000);
        params['timestamp'] = timestamp;
        params.sort();
        var wait_sign = ''
        for (var i in params) {
            wait_sign += i + '=' + params[i] + '&';
        }
        wait_sign = wait_sign.substr(0,wait_sign.length-1);
        console.log(wait_sign)
        sign = md5(wait_sign)
        return sign;
    }
</script>
</html>